<?php

use Illuminate\Support\Facades\DB;
use App\Tools\Common;


$router = app('router');

$router->get('authority', function () {
    return 'authority';
});

$router->get('authority/test', function () {

    // $list = DB::table('public.data_admin')->get()->map(function ($item) {
    //     $userInfo = DB::table('public.data_admin_info')->where('admin_guid', $item->guid)->first();
    //     $guid = Common::getUuid();

    //     DB::table('user.data_user_info')->insert([
    //         'guid' => $guid, // 唯一ID
    //         'nick_name' => $userInfo->nick_name, // 名称
    //         'gender' => 0, // 路由/动作key
    //         'avatar' => $userInfo->avatar, // 父级id
    //         'type' => 2,
    //         'meta' => json_encode(['role_id' => $userInfo->role_guid]), // 平台
    //         'app_id' => '0' // 应用ID
    //     ]);

    //     DB::table('user.data_user_login')->insert([
    //         'user_id' => $guid, // 唯一ID
    //         'username' => $item->admin_name, // 名称
    //         'password' => $item->password, // 路由/动作key
    //         'status' => 1, // 父级id
    //         'type' => 2, // 
    //         'app_id' => '0' // 应用ID
    //     ]);
    // })->toArray();

    // DB::table('authority.data_auth_info')->where('pid', 329)->update([
    //     'pid' => 'e088876ba94341d88e01240acc5ed27c', // 父级id
    // ]);

    // dd($list);

    return 'authority';
});

$router->group(['namespace' => 'Packages\Authority\Http\Controllers', 'prefix' => 'api/auth'], function () use ($router) {
    $router->post('/role/all', 'AdminController@roleAll');
    $router->post('/role/list', 'AdminController@roleList');
    $router->post('/role/add', 'AdminController@roleAdd');
    $router->post('/role/update', 'AdminController@roleUpdate');
    $router->post('/role/auth', 'AdminController@roleAuthAllId');
    $router->post('/role/edit', 'AdminController@editRoleAuth');
    $router->post('/auth/all', 'AdminController@authAll');
    $router->post('/auth/add', 'AdminController@authAdd');
    $router->post('/auth/update', 'AdminController@authUpdate');
    $router->post('/auth/delete', 'AdminController@authDelete');
});
